<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use App;

class Seller extends Model
{
    protected $guarded = [
        'id'
    ];

    protected $with = ['user', 'user.shop'];

    public function user()
    {
        return $this->belongsTo(User::class);
    }

    public function payments()
    {
        return $this->hasMany(Payment::class);
    }

    public function seller_package()
    {
        return $this->belongsTo(SellerPackage::class);
    }


    public function today_visit_history()
    {
        return $this->hasOne(VisitHistoryModel::class, 'seller_id', 'id')->where('current_date', date('Y-m-d'));
    }

    public function yesterday_visit_history()
    {
        return $this->hasOne(VisitHistoryModel::class, 'seller_id', 'id')->where('current_date', date('Y-m-d', time() - 86400));
    }


    public function visit_history()
    {
        return $this->hasMany(VisitHistoryModel::class, 'seller_id', 'id');
    }


    public function getTodayVisitTotalAttribute()
    {
        $today_visit_history = $this->today_visit_history;
        return $today_visit_history->today_visit + $today_visit_history->order_visit + $today_visit_history->refresh_visit;
    }
}
